<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for components\calendar\dateStore.js</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../../prettify.css" />
    <link rel="stylesheet" href="../../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../../index.html">all files</a> / <a href="index.html">components/calendar/</a> dateStore.js
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">2% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>1/50</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>0/28</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>0/7</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">2% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>1/50</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92</td><td class="line-coverage quiet"><span class="cline-any cline-yes">1×</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">const warn = console.warn
// 日期组件
export default class DateStore {
	constructor(options) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >		this.numbers = options.size || 42</span>
<span class="cstat-no" title="statement not covered" >		this.currentMonth = options.currentMonth || false</span>
		let _date = <span class="cstat-no" title="statement not covered" >new Date()</span>
<span class="cstat-no" title="statement not covered" >		this.nowDate = {</span>
			year: _date.getFullYear(), // 年份
			month: _date.getMonth(), // 0-11
			day: _date.getDate() // 1~31
		}
<span class="cstat-no" title="statement not covered" >		this.year = this.nowDate.year </span>// 年
<span class="cstat-no" title="statement not covered" >		this.month = this.nowDate.month </span>// 月
<span class="cstat-no" title="statement not covered" >		this.day = this.nowDate.day </span>// 日
<span class="cstat-no" title="statement not covered" >		this.startInd = 0 </span>// 当月1号在store序号
<span class="cstat-no" title="statement not covered" >		this.endInd = 0 </span>// 当月最后一天在store序号
<span class="cstat-no" title="statement not covered" >		this.store = []</span>
<span class="cstat-no" title="statement not covered" >		this.setToday()</span>
	}
	// 设置日期
	setDate(year, month) <span class="fstat-no" title="function not covered" >{</span>
		// 检测参数是否输入正确
<span class="cstat-no" title="statement not covered" >		if (this._checkYear(year) || this._checkMonth(month)) {</span>
<span class="cstat-no" title="statement not covered" >			return</span>
		}
<span class="cstat-no" title="statement not covered" >		this.year = year</span>
<span class="cstat-no" title="statement not covered" >		this.month = month</span>
<span class="cstat-no" title="statement not covered" >		this.store = [] </span>// 重新赋值
        let start = <span class="cstat-no" title="statement not covered" >new Date(year, month, 1).getDay() </span>// 当月第一天是星期几
        let currentMaxDays = <span class="cstat-no" title="statement not covered" >new Date(year, month + 1, 0).getDate() </span>// 当月的最后一天
        let preMaxDays = <span class="cstat-no" title="statement not covered" >new Date(year, month, 0).getDate() </span>// 上个月最后一天
         // 判断是否只当月
<span class="cstat-no" title="statement not covered" >        if (this.currentMonth) {</span>
<span class="cstat-no" title="statement not covered" >			preMaxDays = undefined</span>
        }
&nbsp;
<span class="cstat-no" title="statement not covered" >		while (start-- &gt; 0) {</span>
<span class="cstat-no" title="statement not covered" >			this.store.unshift(preMaxDays &amp;&amp; preMaxDays--)</span>
		}
<span class="cstat-no" title="statement not covered" >		this.startInd = this.store.length</span>
        // 当月的日期
<span class="cstat-no" title="statement not covered" >        for (let i = 1; i &lt;= currentMaxDays; i++) {</span>
<span class="cstat-no" title="statement not covered" >            this.store.push(i)</span>
        }
<span class="cstat-no" title="statement not covered" >        this.endInd = this.store.length - 1</span>
        // 判断是否只当月
<span class="cstat-no" title="statement not covered" >        if (!this.currentMonth) {</span>
			// 下个月的日期
			let len = <span class="cstat-no" title="statement not covered" >this.store.length</span>
			let i = <span class="cstat-no" title="statement not covered" >1</span>
<span class="cstat-no" title="statement not covered" >			while (len++ &lt; this.numbers) {</span>
<span class="cstat-no" title="statement not covered" >				this.store.push(i++)</span>
			}
        }
	}
	_checkYear(year) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >		if (typeof year !== 'number' || (year &lt; 1970 || year &gt; 2300)) {</span>
<span class="cstat-no" title="statement not covered" >			warn('wrong input year arg!')</span>
<span class="cstat-no" title="statement not covered" >			return true</span>
		}
<span class="cstat-no" title="statement not covered" >		return false</span>
	}
	_checkMonth(month) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >		if (typeof month !== 'number' || (month &lt; 0 || month &gt; 11)) {</span>
<span class="cstat-no" title="statement not covered" >			warn('wrong input month arg!')</span>
<span class="cstat-no" title="statement not covered" >			return true</span>
		}
<span class="cstat-no" title="statement not covered" >		return false</span>
	}
	// 设置年份
	setYear(year) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >		if (this._checkYear(year)) {</span>
<span class="cstat-no" title="statement not covered" >			return</span>
		}
<span class="cstat-no" title="statement not covered" >		this.year = year</span>
<span class="cstat-no" title="statement not covered" >		this.setDate(year, this.month)</span>
	}
	// 设置月份
	setMonth(month) <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >		if (this._checkMonth(month)) {</span>
<span class="cstat-no" title="statement not covered" >			return</span>
		}
<span class="cstat-no" title="statement not covered" >		this.month = month</span>
<span class="cstat-no" title="statement not covered" >		this.setDate(this.year, month)</span>
	}
	// 设置为今天的日期
	setToday() <span class="fstat-no" title="function not covered" >{</span>
<span class="cstat-no" title="statement not covered" >		this.setDate(this.nowDate.year, this.nowDate.month)</span>
	}
}
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sun Feb 24 2019 15:08:50 GMT+0800 (中国标准时间)
</div>
</div>
<script src="../../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../../sorter.js"></script>
</body>
</html>
